%option noyywrap nodefault case-insensitive
%{
#ifndef _YACC_TAB_HEADER_
#define _YACC_TAB_HEADER_
#include "../include/y.tab.h"
#endif
#ifndef _DATABASE_OPERATION_HEADER_
#define _DATABASE_OPERATION_HEADER_
#include "../include/operation.h"
#endif
%}

%%

create {

        return CREATE;}
select {
printf("select\n");
return SELECT;}
insert {printf("insert\n");return INSERT;}
update {printf("update\n");return UPDATE;}
delete {printf("delete\n");return DELETE;}
show {printf("show\n"); return SHOW;}
desc {printf("desc\n"); return DESC;}
databases {return DATABASES;}
database {return DATABASE;}
tables {return TABLES;}
table {return TABLE;}
into {return INTO;}
values {return VALUES;}
where {return WHERE;}
set {return SET;}
primary {return PRIMARY;}
foreign {return FOREIGN;}
as {return AS;}
use {return USE;}
key {return KEY;}


drop {return DROP;}
and {return AND;}
or {return OR;}

not {return NOT;} //  认为与！等价

from {return FROM;}
is {return IS;}
help  {return HELP;}
exit {return EXIT;}
null {return NUL;}
char {return CHAR;}
int {return INT;}
double {return DOUBLE;}
auto_increment {return AUTOINCREMENT;}

!= {yylval.cp = NE; return CP;}
> {yylval.cp = GT;   return CP;}
\< {yylval.cp = LT;  return CP;}
>= {yylval.cp = GE;  return CP;}
\<= {yylval.cp = LE; return CP;}
== { return CP;}
! { return NOT;}


[-+]?[1-9][0-9]*|0 {
    yylval.m_data = (struct Data *)malloc(sizeof(struct Data));
    yylval.m_data->value.i = atoi(yytext);
    yylval.m_data->type=  FIELD_INT;
    printf("%d|\tas number!\n",atoi(yytext));
    return DATA_INT;
    }
[-+]?(([1-9][0-9]*)|0)"."[0-9]+  {
    yylval.m_data = (struct Data *)malloc(sizeof(struct Data));
    yylval.m_data->value.d = atof(yytext);
    printf("%lf| as double!\n",atof(yytext));
    yylval.m_data->type=  FIELD_DOUBLE;
    return DATA_DOUBLE;
    }
`.*` {
    yylval.m_data = (struct Data *)malloc(sizeof(struct Data));
    yytext = yytext+1;
    yylval.m_data->value.m_string = (char *)malloc(sizeof(char) * strlen(yytext));
    strcpy( yylval.m_data->value.m_string,yytext);
    yylval.m_data->value.m_string[strlen(yytext)-1] = '\0';
    yylval.m_data->type = FIELD_STRING;
    printf("read string %s",yytext);
    return DATA_STRING;
    }


[a-zA-Z][a-zA-Z0-9_]+    {
yylval.m_string = (char*)malloc(strlen(yytext));
strcpy(yylval.m_string,yytext) ;
printf("%s|\tas Identify!\n",yytext); return ID;}

[0-9][a-zA-Z0-9_]+  {printf("error:'%s' is not a symbol!\n",yytext);}

; {return DELIMETER;}

"#".*

\n {printf("\nLiSQL> ");}

[ \t] {}

\* {return yytext[0];}
\( {return yytext[0];}
\) {return yytext[0];}
\[ {return yytext[0];}
\] {return yytext[0];}
\{ {return yytext[0];}
\} {return yytext[0];}
, {return yytext[0];}
= {return yytext[0];}

. {printf("%s\n",yytext);}



%%